package com.yanchangapp.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanchangapp.R;
import com.yanchangapp.commom.PlanStatus;
import com.yanchangapp.commom.PlanType;
import com.yanchangapp.model.bean.MgPlanListBean;

import java.util.List;

/**
 * Created by apple on 2019-07-31.
 * description: 我的管理计划adapter...
 */
public class MgPlanListAdapter extends BaseQuickAdapter<MgPlanListBean, BaseViewHolder> {

    public MgPlanListAdapter(int layoutResId, @Nullable List<MgPlanListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, MgPlanListBean mgPlanListBean) {
        // 设置状态...
        baseViewHolder.setText(R.id.tvTitle,mgPlanListBean.getTaskTitle());
        baseViewHolder.setText(R.id.tvPlanStatus,mgPlanListBean.getPlanStatusName());
        baseViewHolder.setText(R.id.tvPlanSource,mgPlanListBean.getPlanSourceName());
        baseViewHolder.setText(R.id.tvPlanType,mgPlanListBean.getPlanTypeName());
        // 设置内容
        baseViewHolder.setText(R.id.tvContent,mgPlanListBean.getContent());
        // 设置是否显示紧急
        if ("紧急".equals(mgPlanListBean.getPriorityName())){
            baseViewHolder.setVisible(R.id.tvImp,true);
        }else {
            baseViewHolder.setVisible(R.id.tvImp,false);
        }

        // 底部四个点击操作按钮
        TextView tvStart = baseViewHolder.getView(R.id.tvStart);
        TextView tvFinish = baseViewHolder.getView(R.id.tvFinish);
        TextView tvCancel = baseViewHolder.getView(R.id.tvCancel);
        TextView tvDelay = baseViewHolder.getView(R.id.tvDelay);
        if (showStart(mgPlanListBean.getPlanStatus())){
            tvStart.setVisibility(View.VISIBLE);
        }else {
            tvStart.setVisibility(View.GONE);
        }

        if (showFinish(mgPlanListBean.getPlanStatus())){
            tvFinish.setVisibility(View.VISIBLE);
        }else {
            tvFinish.setVisibility(View.GONE);
        }

        if (showDelay(mgPlanListBean.getPlanStatus())){
            tvDelay.setVisibility(View.VISIBLE);
        }else {
            tvDelay.setVisibility(View.GONE);
        }

        if (showCancel(mgPlanListBean.getPlanStatus(),mgPlanListBean.getPlanType())){
            tvCancel.setVisibility(View.VISIBLE);
        }else {
            tvCancel.setVisibility(View.GONE);
        }

        baseViewHolder.addOnClickListener(R.id.tvStart)
                .addOnClickListener(R.id.tvFinish)
                .addOnClickListener(R.id.tvDelay)
                .addOnClickListener(R.id.tvCancel);
    }

    private boolean showStart(int planStatus){
        return planStatus == PlanStatus.NO_START.getStatus();
    }

    private boolean showFinish(int planStatus){
        return planStatus == PlanStatus.RUNNING.getStatus();
    }

    private boolean showDelay(int planStatus){
        return planStatus == PlanStatus.NO_START.getStatus() || planStatus == PlanStatus.RUNNING.getStatus();
    }

    private boolean showCancel(int planStatus,int planType){
        return planType != PlanType.GROUP_TASK.getTypeValue() && (planStatus == PlanStatus.NO_START.getStatus() || planStatus == PlanStatus.RUNNING.getStatus());
    }




}
